/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import pojo.Dondathang;
import until.HibernateUtil;

/**
 *
 * @author Admin
 */
public class donDatHangDAO {
    
    public static List<Dondathang>layDonDatHang(){
        List<Dondathang>ds=null;
        Session sc=HibernateUtil.getSessionFactory().openSession();
        try {
            String hql="From DonDatHang";
            Query query =sc.createQuery(hql);
            ds=query.list();
        } catch (Exception e) {
            System.err.print(e);
            sc.close();
        }
        return ds;
    }
    
    //Thêm đơn đạt hàng
    public static boolean  themDonDatHang(Dondathang ddh){
        boolean kq=true;
        Transaction transaction=null;
        Session sc=HibernateUtil.getSessionFactory().openSession();
        try {
            transaction=sc.beginTransaction();
            sc.save(ddh);
            transaction.commit();
        } catch (Exception e) {
            System.err.println(e);
            transaction.rollback();
            kq=false;
        }finally{
            sc.close();
        }
        return kq;
        
    }
    
    public static boolean  capNhatDonDatHang(Dondathang ddh){
        boolean kq=true;
        Transaction transaction=null;
        Session sc=HibernateUtil.getSessionFactory().openSession();
        try {
            transaction=sc.beginTransaction();
            sc.update(ddh);
            transaction.commit();
        } catch (Exception e) {
            System.err.println(e);
            transaction.rollback();
            kq=false;
        }finally{
            sc.close();
        }
        return kq;
    }
    
    
    
}
